package com.java3_17;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo1 {
    private int number;

    public Demo1(){

    }
    public Demo1(int number) {
        this.number = number;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

//    public void add(){
//        synchronized (this){
//            System.out.println("外层");
//            synchronized (this){
//                System.out.println("中层");
//                synchronized (this){
//                    System.out.println("内层");
//                }
//            }
//        }
//    }
    Lock lock = new ReentrantLock();

    public void add(){
        lock.lock();
        try{
            lock.lock();
            System.out.println("外层");
            try {
                System.out.println("内层");
            }finally {
                lock.unlock();
            }
        }finally {
            lock.unlock();
        }

    }
}
